<?php
/**
 * Created by PhpStorm.
 * User: minicart
 * Date: 2018/11/3
 * Time: 13:38
 */

namespace app\admin\service;

use app\models\ParentInformationModel;
use app\models\StudentModel;

class StudentService
{
    /**
     * @param $type
     * @return array
     */
    public function logic($type)
    {
        try {
            $data = input('post.');
            $data['birth'] = $data['birth'] ? $data['birth'] : NULL;
            $data['school_class'] = $data['school_class'] ? $data['school_class'] : '--';
           if ($type == 2) {
                StudentModel::update($data);

			   //家长信息修改 开始
			   $check = (new ParentInformationModel())->where(['student_id'=>$data['id']])->find();
			   if($check['username'] !== $data['guardian_phone']){
				   (new ParentInformationModel())->where(['student_id'=>$data['id']])->update(['username'=>$data['guardian_phone'],'name'=>$data['guardian']]);
			   }
			   //家长信息修改 结束

			   return ['code' => 0, 'msg' => '修改成功'];
            }
        } catch (\Exception $ex) {
            return ['code' => 1, 'msg' => $ex->getMessage()];
        }
    }
}